﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace eBay {
    public interface IResponseType {
    }

    public class eBayResponseType : IResponseType {
        protected DataSet InnerDataSet;

        public eBayResponseType(DataSet responseDataSet) {
            if (responseDataSet == null) return;

            InnerDataSet = responseDataSet;
        }

        public bool HasErrors {
            get {
                return (ResponseStatus == eBay.ResponseStatus.Error || ResponseStatus == eBay.ResponseStatus.ServerError) ? true : false;
            }
        }

        public ResponseStatus ResponseStatus {
            get {
                switch (InnerDataSet.Tables[0].Rows[0]["ack"] + "") {
                    case "Success": return eBay.ResponseStatus.Success;
                    case "Warning": return eBay.ResponseStatus.Warning;
                    case "Error": return eBay.ResponseStatus.Error;
                    default: return eBay.ResponseStatus.ServerError;
                }
            }
        }
    }

    public class GetSearchKeywordsRecommendationResponseType : eBayResponseType, IResponseType {
        protected string InnerKeywords;

        public GetSearchKeywordsRecommendationResponseType(DataSet responseDataSet)
            : base(responseDataSet) {
            InnerKeywords = responseDataSet.Tables[0].Rows[0]["keywords"] + "";
        }

        public string Keywords {
            get {
                return InnerKeywords;
            }
        }
    }
    
    public class FindItemsResponseType : eBayResponseType, IResponseType {
        public FindItemsResponseType(DataSet responseDataSet) : base(responseDataSet) { }

        public DataRowCollection Items {
            get {
                if (InnerDataSet.Tables.Contains("Item")) {
                    return InnerDataSet.Tables["Item"].Rows;
                }
                return null;
            }
        }
    }


    public class FindItemsAdvancedResponseType : eBayResponseType, IResponseType {
        public FindItemsAdvancedResponseType(DataSet responseDataSet) : base(responseDataSet) { }

        public DataRowCollection Items {
            get {
                if (InnerDataSet.Tables.Contains("Item")) {
                    return InnerDataSet.Tables["Item"].Rows;
                }
                return null;
            }
        }
    }


    public class FindItemsByCategoryResponseType : eBayResponseType, IResponseType {
        public FindItemsByCategoryResponseType(DataSet responseDataSet) : base(responseDataSet) { }

        public DataRowCollection Items {
            get {
                if (InnerDataSet.Tables.Contains("Item")) {
                    return InnerDataSet.Tables["Item"].Rows;
                }
                return null;
            }
        }
    }
}
